﻿namespace DoNet.ApiHttpClient
{
    /// <summary>
    /// 
    /// </summary>
    public interface IHttpClient
    {
        #region 同步
        /// <summary>
        /// 同步发送请求方法
        /// </summary>
        /// <param name="method">请求方式</param>
        /// <param name="url">不包含（http/https + : + 域名 + /）,只要域名后面的</param>
        /// <param name="parameters">请求参数</param>
        /// <param name="certId">证书ID，默认为空不使用证书，尽量使用商户号为证书的文件名称（请求头Headers添加“X-Cert-ID”）</param>
        /// <param name="headers">请求头</param>
        /// <param name="contentType">参数的类容类型</param>
        /// <param name="timeout">请求超时时间（单位秒），默认为100秒</param>
        /// <param name="retryCount">重试次数，默认为2次</param>
        /// <returns></returns>
        /// <exception cref="NotSupportedException"></exception>
        /// <exception cref="HttpRequestException"></exception>
        HttpResponseMessage SendRequest(HttpMethod method, string url, Dictionary<string, object>? parameters = null, string certId = "", Dictionary<string, string>? headers = null, string contentType = "application/json", int timeout = 100, int retryCount = 2);
        /// <summary>
        /// 同步上传文件方法
        /// </summary>
        /// <param name="apiUrl">不包含（http/https + : + 域名 + /）,只要域名后面的</param>
        /// <param name="formData">表单字段列表</param>
        /// <param name="fileDictionary">文件列表（HTTP内容的名称，文件完整路径名称）</param>
        /// <param name="headers">请求头</param>
        /// <param name="timeout">请求超时时间（单位秒），默认为100秒</param>
        /// <param name="retryCount">重试次数，默认为2次</param>
        /// <returns></returns>
        /// <exception cref="HttpRequestException"></exception>
        HttpResponseMessage UploadFiles(string apiUrl, Dictionary<string, string>? formData = null, Dictionary<string, string>? fileDictionary = null, Dictionary<string, string>? headers = null, int timeout = 100, int retryCount = 2);
        #endregion 同步

        #region 异步
        /// <summary>
        /// 异步发送请求方法
        /// </summary>
        /// <param name="method">请求方式</param>
        /// <param name="url">不包含（http/https + : + 域名 + /）,只要域名后面的</param>
        /// <param name="parameters">请求参数</param>
        /// <param name="certId">证书ID，默认为空不使用证书，尽量使用商户号为证书的文件名称（请求头Headers添加“X-Cert-ID”）</param>
        /// <param name="headers">请求头</param>
        /// <param name="contentType">参数的类容类型</param>
        /// <param name="timeout">请求超时时间（单位秒），默认为100秒</param>
        /// <param name="retryCount">重试次数，默认为2次</param>
        /// <returns></returns>
        /// <exception cref="NotSupportedException"></exception>
        /// <exception cref="HttpRequestException"></exception>
        Task<HttpResponseMessage> SendRequestAsync(HttpMethod method, string url, Dictionary<string, object>? parameters = null, string certId = "", Dictionary<string, string>? headers = null, string contentType = "application/json", int timeout = 100, int retryCount = 2);
        /// <summary>
        /// 异步上传文件方法
        /// </summary>
        /// <param name="apiUrl">不包含（http/https + : + 域名 + /）,只要域名后面的</param>
        /// <param name="formData">表单字段列表</param>
        /// <param name="fileDictionary">文件列表（HTTP内容的名称，文件完整路径名称）</param>
        /// <param name="headers">请求头</param>
        /// <param name="timeout">请求超时时间（单位秒），默认为100秒</param>
        /// <param name="retryCount">重试次数，默认为2次</param>
        /// <returns></returns>
        /// <exception cref="HttpRequestException"></exception>
        Task<HttpResponseMessage> UploadFilesAsync(string apiUrl, Dictionary<string, string>? formData = null, Dictionary<string, string>? fileDictionary = null, Dictionary<string, string>? headers = null, int timeout = 100, int retryCount = 2);
        #endregion 异步
    }
}
